'use strict';

const _ = require('lodash');
const path = require('path');
const {Controller} = require('ee-core');
const {
    app: electronApp, clipboard , sessionpowerMonitor, screen, nativeTheme, dialog
} = require('electron');
const Log = require('ee-core/log');
const fs = require("fs")
/**
 * Requests控制器
 * @class
 */
class SystemController extends Controller {

    constructor(ctx) {
        super(ctx);
    }


    async copyClipboard(arg){
        const {text=""} = arg
        Log.info(`${arg} 置入剪辑版`)
        return clipboard.writeText(text)
    }




    async selectFolder(arg){
        const filePaths = dialog.showOpenDialogSync({
            title:arg === 0 ? "选择文件":'选择目录',
            properties:arg === 0 ? ['openFile','createDirectory','promptToCreate','multiSelections']:['openDirectory','createDirectory','promptToCreate'],
            message:arg === 0 ? "选择文件":'选择目录',
            filters: [
                // { name: 'Images', extensions: ['jpg', 'png', 'gif'] },
                { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] },
                // { name: 'Custom File Type', extensions: ['as'] },
                // { name: 'All Files', extensions: ['*'] }
            ]
        });
        if (_.isEmpty(filePaths)) {
            return null
        }
        return filePaths;

    }

    selectFormVideoNumber(arg){
        let count =0
       fs.readdirSync(arg.filePath).forEach((file)=>{
           const filePath = path.join(arg.filePath,file);
           const stat = fs.statSync(filePath)
           if(stat.isFile() && path.extname(file).toLowerCase()===".mp4"){
               count++;
           }
       })
        return count

    }



}

SystemController.toString = () => '[class SystemController]';
module.exports = SystemController;
